package org.aeon.client.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.client.context.GlobalContext;
import org.aeon.constant.GroupDisplayType;
import org.aeon.entity.dto.ChatGroupDto;
import org.aeon.message.response.GroupsListResponseMessage;

import java.util.List;
import java.util.Map;

import static org.aeon.client.context.MessageMap.MessageContextKey.GroupMapList;


/**
 * @author: MissingAeon
 * @date: 2024/2/19 14:41
 * @description: 组列表响应处理程序
 */
@Slf4j
@ChannelHandler.Sharable
public class GroupsListResponseHandler extends SimpleChannelInboundHandler<GroupsListResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupsListResponseMessage msg) throws Exception {
        if (msg.isSuccess()) {
            final Map<GroupDisplayType, List<ChatGroupDto>> map = msg.getMap();
          GlobalContext.getContext().getMessageMap().set(GroupMapList, map);
        }
        ctx.fireChannelRead(msg);
    }
}
